<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '用户';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',
            'password',
            'email:email',
            // 'auth_key',
            // 'access_token',
            [
                'attribute' => 'created_at',
                'format' => ['date', 'php:Y-m-d']
            ],
            [
                'attribute' => 'updated_at',
                'format' => ['date', 'php:Y-m-d']
            ],
            [
                'label'=>'角色',
                'value'=>function($data){
                    $roles = Yii::$app->authManager->getRolesByUser($data['id']);
                    return $roles?current($roles)->description:'';
                },
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'template'=>'{view}{update}{delete}{assign}',
                'buttons'=>[
                    'assign' => function ($url, $model, $key) {
                        return Html::a('&nbsp;<span class="glyphicon glyphicon-user"></span>', $url, ['title' => '修改权限'] );
                    },
                ]
            ],
        ],
    ]); ?>
</div>
